package demo05_NotSafeCollections;

import java.util.Set;
import java.util.UUID;
import java.util.concurrent.CopyOnWriteArraySet;

/**
 * @author kunkun
 * @className Test01_list
 * @Description 用于测试不安全的list类
 * @date 2025/3/5 20:32
 */
public class Test02_map {
    public static void main(String[] args) {

//        Set<String> set = new HashSet<>();  //不安全的set
//        Set<String> set = Collections.synchronizedSet(new HashSet<>()); //1. 使用Collections进行转换
        Set<String> set = new CopyOnWriteArraySet<>();//2. 使用juc下的类

        for (int i = 0; i < 20; i++) {
            new Thread(() -> {
                set.add(UUID.randomUUID().toString().substring(0, 5));
                System.out.println(set);
            }, "Thread-" + i).start();
        }
    }
}
